<template>
    <div class="teamWrap">
        <div class="title">编辑成员<router-link  to="/open/team"><button class="new"><i class="el-icon-back"></i>返回</button></router-link></div>
        <el-form ref="form" :model="form" label-width="80px">
          <el-form-item label="账号类型">
              <el-input :value="isMainAccount" disabled></el-input>
          </el-form-item>
          <el-form-item label="账号">
              <el-input v-model="form.phone" disabled></el-input>
          </el-form-item>
          <el-form-item label="身份证号码">
              <el-input v-model="form.id_card" type="number"></el-input>
          </el-form-item>
          <el-form-item label="姓名">
              <el-input v-model="form.name"></el-input>
          </el-form-item>
          <div class="myRow">
                 <span>性别</span><el-select v-model="form.sex" placeholder="请选择">
                  <el-option label="男" value="男"></el-option>
                  <el-option label="女" value="女"></el-option>
                </el-select>
          </div>
          <el-form-item label="职位">
              <el-input v-model="form.job"></el-input>
          </el-form-item>
          <div class="onSubmit">              
            <el-form-item>
                <el-button type="primary" @click="onSubmit" icon="el-icon-upload">提交</el-button>
            </el-form-item>
          </div>
      </el-form>
    </div>
</template>

<script>
  import _ from 'underscore'
  import $ from 'jquery'
    export default {
        data() {
      return {
        form:{
         id:0,
         name:"用户名称",
         phone:"用户手机号",
         job:"职位",
         email:"邮箱",
         address:"用户地址",
         sex:"男",
         id_card:"身份证号码",
         type:0
        },
        uid:0,
        isMainAccount:'子账户'
      }
    },
    activated(){
           $('.el-button--primary')[0].setAttribute("style","background-color: rgb(58, 19, 90) !important;border-color: rgb(58, 19, 90) !important")
      this.uid=this.$route.params.uid
      this.getUserInfo()
    },
    methods: {
      handleEdit(index, row) {
        console.log(index, row);
      },
      getUserInfo(){
        var data={token:localStorage.getItem('token'),id:this.uid}
        this.$http.post(this.$store.getters.serverIp+'get_userinfo',data).then((response)=>{
            if(response.data.success){
                this.form=response.data.data
                if(response.data.type==1){
                  this.isMainAccount='主账户'
                }else{
                  this.isMainAccount='子账户'
                }
            }
        })
      },
      onSubmit(){
        var data={id_card:this.form.id_card,name:this.form.name,sex:this.form.sex,job:this.form.job,token:localStorage.getItem('token'),id:this.form.id}
         var hasEmpty=false
          _.each(data,(value)=>{
              if($.trim(value)==''){
                  hasEmpty=true
              }
          })
          if(hasEmpty){
              this.$message.error({message:'信息不能为空',duration:1000});
              return
          }
          const loading = this.$loading({
            lock: true,
            text: '成员编辑中',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
          });
        this.$http.post(this.$store.getters.serverIp+'edit_userinfo',data).then((response)=>{
          loading.close()
            if(response.data.success){
              this.$message.success({message:response.data.info,duration:1000});
              this.$router.push('/open/team')
            }else{
              this.$message.error({message:response.data.info,duration:1000});
            }
        })
      }
    }
    }
</script>
<style lang="less" >
    .teamWrap{
         .el-form{
            width: 78%;
            margin: 0 auto;
            margin-top: 25px;
        }
        .myRow{
          width: 40.5%;
          margin: 0 auto;
          margin-top: 31px;
          span{
            font-size: 14px;
            color: #606266;
            margin-right: 12px;
          }
        }
        .el-form-item__label{
            position: relative !important;
            top: 33px !important;
            width: 120px !important;
            left: -42px;
        }
        .onSubmit{
            .el-form-item--small{
                border-top: 1px solid #ccc !important;
                text-align: center !important;
                width: 100% !important;
                margin-top: 60px !important;
            }
            .el-form-item__content{
                margin: 0 !important;
            }
            .el-button--primary{
                margin-top: 10px !important;
            }
        }
        .el-form-item{
            width: 45%;
            margin: 0 auto;
        }
        .logoImg{
            margin-top: 19px;
            max-width:120px;
        }
        .el-table__header-wrapper{
        font-size: 22px !important;
        }
        tr.el-table__row {
            font-size: 18px;
        }
    }
</style>>